/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.bussines.ejbs;

import cl.bussines.entities.ValorHora;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author Vogel
 */
@Stateless
public class ValorHoraFacade extends AbstractFacade<ValorHora> {
    @PersistenceContext(unitName = "TallerStudioPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ValorHoraFacade() {
        super(ValorHora.class);
    }
    
    public void crearNuevo(ValorHora valor){
        try{
            String sql ="select v from ValorHora v where v.estado = :estado";
            TypedQuery<ValorHora> query = getEntityManager().createQuery(sql, ValorHora.class);
            query.setParameter("estado", 1);
            ValorHora antiguo = query.getSingleResult();
            antiguo.setEstado(0);
            edit(antiguo);
        }catch(Exception e){}
        create(valor);
    }
}
